<?php
include "../soar/soar.inc";

function main($soar)
{/*{{{*/
    $secure=$soar->secure();

    $plain="红日初升，其道大光。河出伏流，一泻汪洋。".
        "潜龙腾渊，鳞爪飞扬。乳虎啸谷，百兽震惶。".
        "鹰隼试翼，风尘吸张。奇花初胎，矞矞皇皇。".
        "干将发硎，有作其芒。". 
        "天戴其苍，地履其黄。纵有千古，横有八荒。".
        "前途似海，来日方长。".
        "美哉，我少年中国，与天不老！".
        "壮哉，我中国少年，与国无疆！";
    $soar->view['plain']=$plain;

    $enc=$secure->encrypt("0000", $plain);
    if($enc == null)
    {
        $soar->view['enc']=$soar->last_error;
        return;
    }
    $soar->view['enc']=$enc;

    $dec=$secure->decrypt($enc);
    if($dec == null)
    {
        $soar->view['dec']=$soar->last_error;
        return;
    }
    $soar->view['dec']=$dec;

    $sign=$secure->sign($plain);
    if($sign == null)
    {
        $soar->view['sign']=$soar->last_error;
        return;
    }
    $soar->view['sign']=$sign;

    $res=$secure->verify("0000", $plain, $sign);
    if($res == false)
    {
        $soar->view['verify']=$soar->last_error;
        return;
    }
    $soar->view['verify']="成功";

    $enc_sign=$secure->encsign("0000", $plain);
    if($enc_sign == null)
    {
        $soar->view['enc_sign']=array('enc'=>$soar->last_error, 'sign'=>"");
        return;
    }
    $soar->view['enc_sign']=$enc_sign;

    $vrfy_dec=$secure->vrfydec("0000",
            $enc_sign['enc'], $enc_sign['sign']);
    if($vrfy_dec == null)
    {
        $soar->view['vrfy_dec']=$soar->last_error;
        return;
    }
    $soar->view['vrfy_dec']=$vrfy_dec;
}/*}}}*/

$soar=new soar();
main($soar);
$soar->close();
$VIEW=$soar->view;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<?php
echo "明文：".$VIEW['plain']."<br/>\n";
echo "密文：".$VIEW['enc']."<br/>\n";
echo "解密：".$VIEW['dec']."<br/>\n";
echo "签名：".$VIEW['sign']."<br/>\n";
echo "校验：".$VIEW['verify']."<br/>\n";
echo "密文+签名：".$VIEW['enc_sign']['enc']."<br/>\n";
echo "           ".$VIEW['enc_sign']['sign']."<br/>\n";
echo "校验+解密：".$VIEW['vrfy_dec']."<br/>\n";
?>
</body>
</html>
